import java.sql.SQLOutput;

class Animal{
    public String name;
    public int age;
    public String color;

    public Animal(String name, int age, String color) {
        this.name = name;
        this.age = age;
        this.color = color;
    }

    public void way(){
        System.out.println("Animal基类！");
    }
}

class Dog extends Animal{
    public String action;

    public Dog(String name, int age, String color, String action) {
        super(name, age, color);
        this.action = action;
    }

    public void way(){
        System.out.println(this.name+this.action+"的速度很快……");
    }
}

class Bird extends Animal{
    public String board;

    public Bird(String name, int age, String color, String board) {
        super(name, age, color);
        this.board = board;
    }

    public void way(){
        System.out.println(this.name+"是"+this.board+"种类……");
    }
}


public class Test {

    public static void action_fun(Animal animal){
        animal.way();
    }

    public static void main(String[] args) {
        //下面向上转型
        //1、直接赋值方式向上转型
        Animal animal1 = new Dog("哈士奇",3,"黑白","跑");//向上转型
        animal1.way();
        Animal animal2 = new Bird("雪雕",12,"黑金色","稀有");
        animal2.way();
        System.out.println("====================================================");

        //2、通过参数进行向上转型
        Dog dog = new Dog("哈士奇",3,"黑白","跑");
        action_fun(dog);
        Bird bird = new Bird("雪雕",12,"黑金色","稀有");
        action_fun(bird);

        //3、也可以通过返回值向上转型，更具传入参数的动物类型，在函数中创建对应的类对象，返回是的时候，返回基类对象类型

    }
}
